package com.youkeda.dewu.api;

import com.youkeda.comment.model.Paging;
import com.youkeda.comment.model.Result;
import com.youkeda.dewu.model.Order;
import com.youkeda.dewu.param.QueryOrderParam;
import com.youkeda.dewu.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 刘正星
 * @version 1.0.0
 * @ClassName OrderApi.java
 * @Description TODO
 * @createTime 2020年10月09日 12:52:00
 */
@RestController
@RequestMapping("/api/order")
public class OrderApi {
    @Autowired
    private OrderService orderService;

    @PostMapping("/add")
    public Result<Order> add(Order order, HttpServletRequest request){
           Result<Order> result = new Result<>();
           result.setSuccess(true);
        if (order == null){
            result.setSuccess(false);
            result.setMessage("order is null");
            return result;
        }
           Object userId = request.getSession().getAttribute("userId");
           if (userId == null){
               result.setSuccess(false);
               result.setMessage("userId is null");
               return result;
           }
           order.setUserId((Long) userId);
           Order retrunOrder = orderService.add(order);

           result.setData(retrunOrder);
           return result;
    }
    @GetMapping("/queryrecentpaysuccess")
    public Result<Paging<Order>> queryRecentpaySuccess(QueryOrderParam param){
        Result<Paging<Order>> result = new Result<>();
        result.setSuccess(true);
        if (param == null){
            result.setSuccess(false);
            result.setMessage("param is null");
            return result;
        }
        Paging<Order> orderPaging = orderService.queryRecentPaySuccess(param);
        if (orderPaging == null){
            result.setSuccess(false);
            result.setMessage("orderPaging is null");
            return result;
        }
        result.setData(orderPaging);
        result.setMessage("successful");
        return result;
    }
}
